<?php header('Content-Type: text/html; charset=utf-8');
?>
<div id="form_comment">
    <form onsubmit="return validateForm();" method="post" action="comment.php">

        <p><input type="hidden" name="entry" id="entry" value="{post_id}" />
            <strong><label for="name">Họ tên:</label></strong> <input type="text" name="name" id="name" size="25" value="{hoten}"></input><br /><br/>
            <strong><label for="email">E-mail:</label></strong> <input type="text" name="email" id="email" size="25" value="{email}"></input><br /><br/>
            <strong><p> <lable id="error"></lable></p></strong> <br/>
        <strong><label for="comment">Lời nhận xét:</label></strong><br />
        <textarea cols="30" rows="7" name="comment" id="wysiwyg">{comment}</textarea></p>
		<input type="hidden" value="{commentId}" name="commentid" id="commentid">
        <p><input type="submit" name="submit_comment" id="submit_comment" value="{action}" />
            <input onclick="resetComment()" type="button" name="reset_comment" id="reset_comment" value="Làm lại" />
        </p>
    </form>
    <div>

    </div>
</div>


<script type='text/javascript'>

    function resetComment(){
        // Make quick references to our fields
        var title = document.getElementById('name');
        title.value = '';
        var content = document.getElementById('wysiwyg');
        content.value = '';
        var email = document.getElementById('email');
        email.value = '';
    }

    function validateForm(){
        // Make quick references to our fields
        var title = document.getElementById('name');
        var content = document.getElementById('wysiwyg');
        var email = document.getElementById('email');	
        // Check each input in the order that it appears in the form!
        if(isEmpty(title, "*Chưa nhập tiêu đề") || 
            isEmpty(email,"*Chưa nhập email") ||
            (!validateEmail(email, "*Email không hợp lệ")||
            isEmpty(content,"*Chưa nhập nội dung"))){
            return false;
        }
        return true;
	
    }
    function isEmpty(elem, helperMsg){
        if(elem.value.length == 0){
            var errorLable = document.getElementById('error');
            errorLable.innerHTML = helperMsg;
            errorLable.style.fontWeight = "Bold";
            errorLable.style.color = "Red";
            errorLable.style.fontFamily="arial,sans-serif";
            errorLable.style.fontSize = "10px";
            elem.focus(); // set the focus to this input
            return true;
        }
        return false;
    }
    
    function validateEmail(elem,helperMsg){
        var emailPattern = /^[a-zA-Z0-9._]+[a-zA-Z0-9]+@[a-zA-Z0-9]+\.[a-zA-Z]{2,4}$/;  
        var valid = emailPattern.test(elem.value);
        if(valid == false)
        {
            var errorLable = document.getElementById('error');
            errorLable.innerHTML = helperMsg;
            errorLable.style.fontWeight = "Bold";
            errorLable.style.color = "Red";
            errorLable.style.fontFamily="arial,sans-serif";
            errorLable.style.fontSize = "10px";
            elem.focus(); // set the focus to this input
            return false;
                
        }
        return true;
    }   
  
</script>
